<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('授权列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>

<body class="gray-bg">
<div class="ui-layout-center">
    <form id="region-form">
        <div class="container-div">
            <div class="row">

                <div class="col-sm-12 select-table table-striped">
                    <h4 class="form-header h4">中征平台授权列表</h4>
                    <table id="authorization"></table>
                </div>
                <input type="hidden" name="CREDITCODE" id="CREDITCODE" value="zzz">
                <input type="hidden" name="CREDITNO" id="CREDITNO" value="zzz">
                <input type="hidden" name="CREDITNAME" id="CREDITNAME" value="zzz">
                <input type="hidden" name="hxqyName" id="hxqyName" value="zzz">
                <input type="hidden" name="hxqyCode" id="hxqyCode" value="zzz">
                <input type="hidden" name="table" id="table" value="ZZ_YFZK_JS_up">

                <from id="ordinary-form">
                    <div class="col-sm-12 select-table table-striped">
                        <h4 class="form-header h4"><label id="historyDataLabel">历史数据</label></h4>
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="push()">推送至中征平台</a>
                        <table id="historyData"></table>
                    </div>
                </from>

            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">
    var prefix = ctx + 'middlesignYi';

    $(function () {
        var authorizationList = {
            url: prefix + '/getAuthorizationList',
            id: "authorization",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: false,
            columns: [
                {
                    field: 'CREDIT_NAME',
                    title: '供应商名称'
                },
                {
                    field: 'CREDIT_CODE',
                    title: '供应商统一社会信用代码'
                },
                {
                    field: 'CREDIT_NO',
                    title: '授权编号'
                },
                {
                    field: 'HIS_START_DATE',
                    title: '历史数据起始日'
                },
                {
                    field: 'HIS_END_DATE',
                    title: '历史数据截止日'
                },
                {
                    field: 'hxqyName',
                    title: '核心企业名称'
                },
                {
                    field: 'hxqyCode',
                    title: '核心企业统一社会信用代码'
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="findHistoryData(\'' + row.CREDIT_CODE + '\',\'' + row.CREDIT_NO + '\',\'' + row.CREDIT_NAME + '\',\'' + row.hxqyName + '\',\'' + row.hxqyCode + '\')"><i class="fa fa-edit"></i>查看历史数据</a> ');
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(authorizationList);

        var historyData = {
            url: prefix + '/getHistoryData',
            id: "historyData",
            updateUrl: prefix + "/edit/{id}",
            modalName: "历史数据",
            height: 600,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: false,
            columns: [
                {
                    field: 'ID',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'CREDIT_CODE',
                    title: '供应商统一社会信用代码*'
                },
                {
                    field: 'CREDIT_NAME',
                    title: '供应商名称*'
                },
                {
                    field: 'CREDIT_NO',
                    title: '授权编号*'
                },
                {
                    field: 'ORDERS_SUM_AMT',
                    title: '本年度应付账款凭证总金额*',
                    visible: false
                },
                {
                    field: 'ORDERS_COUNT',
                    title: '本年度已归档发票总数'
                },
                {
                    field: 'ORDERS_BALANCE',
                    title: '本期末应付账款凭证总余额*',
                    visible: false
                },
                {
                    field: 'mark1',
                    title: 'aaa',
                    visible: false
                },
                {
                    field: 'ORDERS_CANCEL_AMT',
                    title: '本年度对该供应商付款总金额*',
                    visible: false
                },
                {
                    field: 'PAY_LAST_DATE',
                    title: '本年度最后一次付款日'
                },
                {
                    field: 'YEAR',
                    title: '会计年份*'
                },
                {
                    field: 'ORDER_CODE',
                    title: '应付账款凭证号*'
                },
                {
                    field: 'ORDER_AMT',
                    title: '应付账款凭证金额*'
                },
                {
                    field: 'ORDER_DATE',
                    title: '应付账款凭证产生日*'
                },
                {
                    field: 'prepareddate',
                    title: '应付账款凭证产生日1',
                    visible: false
                },
                {
                    field: 'EXPLANATION',
                    title: '摘要',
                    visible: false
                },
                {
                    field: 'LOCALDEBITAMOUNT',
                    visible: false
                },
                {
                    field: 'PAY_LAST_DATE_SINGLE',
                    title: '对账款凭证最后一次付款日'
                },
                {
                    field: 'ORDER_BALANCE',
                    title: '应付账款凭证余额'
                },
                {
                    field: 'ORDER_YEAR',
                    title: '年份*'
                },
                {
                    field: 'COMPANY_CODE',
                    title: '具体债务公司机构信用代码'
                },
                {
                    field: 'Voucher_No',
                    title: 'zzz',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.ID + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(historyData);
    });

    function findHistoryData(CREDITCODE,CREDITNO,CREDITNAME, hxqyName,hxqyCode) {
        $("#CREDITCODE").val(CREDITCODE);
        $("#CREDITNO").val(CREDITNO);
        $("#CREDITNAME").val(CREDITNAME);
        $("#hxqyName").val(hxqyName);
        $("#hxqyCode").val(hxqyCode);
        $("#table").val('ZZ_YFZK_JS_up');

        $("#historyData").bootstrapTable('refresh');

        /*
        $.ajax({
            url: prefix + '/getHistoryDataCount',
            data: {
                "name": CREDIT_NAME
            },
            success: function (data) {
                if (data.ORDERS_SUM_AMT == null && data.ORDERS_BALANCE == null && data.ORDERS_CANCEL_AMT == null) {
                    data.ORDERS_SUM_AMT = 0;
                    data.ORDERS_BALANCE = 0;
                    data.ORDERS_CANCEL_AMT = 0;
                }
                console.log(data);
                document.getElementById('historyDataLabel').innerHTML = CREDIT_NAME + "共" + data.shuliang + "条历史数据&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;本年度应付账款凭证总金额:" + data.ORDERS_SUM_AMT + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;本期末应付账款凭证总余额:" + data.ORDERS_BALANCE + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;本年度对该供应商付款总金额:" + data.ORDERS_CANCEL_AMT;
            }
        })
        */
    }

    function push() {
        var data = $("#historyData").bootstrapTable('getData');
        var CREDITCODE = $("#CREDITCODE").val();
        var CREDITNO = $("#CREDITNO").val();
        var CREDITNAME = $("#CREDITNAME").val();
        var hxqyName = $("#hxqyName").val();
        var hxqyCode = $("#hxqyCode").val();
        var table = $("#table").val();

        $.ajax({
            type: "POST",
            url: prefix + '/pushHistoryData',
            data: {'data': JSON.stringify(data), "CREDITCODE": CREDITCODE,"CREDITNO": CREDITNO, "CREDITNAME": CREDITNAME, "hxqyName": hxqyName,"hxqyCode": hxqyCode, "table": table},
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    alert("推送成功");
                } else {
                    alert("推送错误:" + data.data);
                }
            }
        })
    }
</script>
</body>
</html>